﻿using GenericWin;
using ScreenConnection;
using GeneralServices.ViewModel;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using WpfApplication1.TestComposantV2;
using WpfApplication1.TestValid;

namespace WpfApplication1
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

        private class MC : GenericWin.GenericMainController
        {
            //private int etapeval = 0;

            public MC()
                : base(true)
            {

            }

            public override bool Authentificate(Dictionary<string, string> values)
            {
                return true;
            }

            public override void InitApplication()
            {
                ServicesSingle.Register<NvleSessionVM>();
            }

            public override GenericUserControl DoAction(GenericWin.MenuItemViewModel item)
            {
                GenericUserControl g = null;

                // Deux facons d'isntancier le VM
                if (item.Id == "Nouvelle session2")
                    g = new NvleSession() { VM = ServicesSingle.Get<NvleSessionVM>() };
                else if (item.Id == "TATA")
                    g = new Test();
                else if (item.Id == "Test Composant V2 - T")
                    g = new UserControlComposantRefV2();
                else if (item.Id == "Test Composant V2 - VALID")
                {
                    TestValidUOW test = new TestValidUOW();
                    test.TestValidUnitofWork();
                    return null;
                }
                else
                {
                    Configuration config = GenericMainController.Config;
                    EcranConnection ecran = new EcranConnection(config.Version, config.NomApplication, config.Env, this, null);
                    ecran.Show();
                    base.LogOff();
                    return null;
                }

                return g;
            }

            public override List<GenericWin.MenuItemViewModel> BuildMenu()
            {
                List<MenuItemViewModel> _list = new List<MenuItemViewModel>();

                MenuItemViewModel menuSession = new MenuItemViewModel("Session");

                MenuItemViewModel menuSession2 = new MenuItemViewModel("Session2", "Session2", null, "Ecran de nouvelle session");
                menuSession2.Children.Add(new MenuItemViewModel("Nouvelle session2", "Nouvelle session2", new Uri(@"C:\Users\legouellecs\Pictures\Audi-RS3-Sportback-prix.jpg"), "Ecran de nouvelle session2"));

                menuSession.Children.Add(menuSession2);
                menuSession.Children.Add(new MenuItemViewModel("Nouvelle session"));
                menuSession.Children.Add(new MenuItemViewModel("Log out"));

                MenuItemViewModel menuAide = new MenuItemViewModel("Aide");
                menuAide.Children.Add(new MenuItemViewModel("A propos"));
                menuAide.Children.Add(new MenuItemViewModel("TATA"));

                MenuItemViewModel menuComV2 = new MenuItemViewModel("Test Composant V2");
                menuComV2.Children.Add(new MenuItemViewModel("Test Composant V2 - T"));
                menuComV2.Children.Add(new MenuItemViewModel("Test Composant V2 - VALID"));

                _list.Add(menuSession);
                _list.Add(menuAide);
                _list.Add(menuComV2);

                return _list;
            }

            public override Configuration BuildConfiguration()
            {
                Configuration c = new Configuration();
                c.Env = "DEV";
                c.InstanceBDD = "DSPP";
                c.LibelleEnvironnement = "Développement";
                c.NomApplication = "Emballage";
                c.Version = "1.0.0";
                c.LoginUserConnecte = "legouellecs";
                return c;
            }

            public override void LongLoadingApplication(Window w, int etape, int nbMaxEtape, String message)
            {
                Splashscreen s = w as Splashscreen;
                if(s != null)
                    s.SetProgress(message, etape + 1, 4);
            }

            public override void ShortLoadingApplication(Window w, int etape, int nbMaxEtape, String message)
            {
                Splashscreen s = w as Splashscreen;
                if (s != null)
                    s.SetProgress(message, etape + 1, 4);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SplashScreenConfig config = new SplashScreenConfig()
            {
                NbEtapeShortLoaded = 1,
                DelayActionsShort = new Int32[] { 500},
                NameActionsShort= new string[] { "TUTU"}
            };

            EcranConnection sc = new EcranConnection("1.0.0", "Emballage", "Développement", new MC(), config);
            sc.Show();
        }
    }
}
